define(['jquery'],
function($) {
	var Video = function(scalingFactor, x, y) {
		// Create main canvas
		Video._canvas = document.createElement('canvas');
		Video._canvasContext = Video._canvas.getContext('2d');
		Video._canvas.style.position = 'absolute';
		Video._canvas.style.left = x + 'px';
		Video._canvas.style.top = y + 'px';
		$('body').append(Video._canvas);

		// Create screen canvas used for double buffering
		Video._screen = document.createElement('canvas');
		Video._screenContext = Video._screen.getContext('2d');

		// Save scaling factor
		Video._scalingFactor = scalingFactor;
	}

	Video.initScreen = function(width, height) {
		Video._screen.width = width * Video._scalingFactor;
		Video._screen.height = height * Video._scalingFactor;
		Video._canvas.width = width * Video._scalingFactor;
		Video._canvas.height = height * Video._scalingFactor;
	}

	Video.setPixel = function(x, y, color) {
		var r = (color >> 16) & 0xFF;
		var g = (color >> 8) & 0xFF;
		var b = color & 0xFF;
		Video._screenContext.fillStyle = "rgb(" + r + "," + g + "," + b + ")";
		Video._screenContext.fillRect(x * Video._scalingFactor,
			y * Video._scalingFactor,
			Video._scalingFactor,
			Video._scalingFactor);
	}

	Video.update = function() {
		Video._canvasContext.drawImage(Video._screen, 0, 0, Video._canvas.width,
			Video._canvas.height);
	}

	return Video;
});